// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: implementation of CImplHeader.
//   $Id$
#include "stdafx.h"
#include "implheader.h"
#include "ImplContextualValue.h"
#include "model.h"
CImplHeader::CImplHeader(CImplContextualValue * pName,CImplContextualValue * pValue)
	:m_pNameResolver(pName)
	,m_pValueResolver(pValue)
{
}

CImplHeader::~CImplHeader(void)
{
	delete m_pNameResolver;
	delete m_pValueResolver;
}

HRESULT CImplHeader::GetHeaders(CImplModel * pModel,IXMLDOMNode * pContext,CComBSTRMap & mHeaders)
{
	HRESULT hr = S_OK;
	if(m_sNodeset)
	{
		CComPtr<IXPathResult> pResult;
		pModel->getInstanceNodeList(m_sNodeset,pContext,false,&pResult);
		unsigned long len;
		pResult->get_snapshotLength(&len);
		for(unsigned long i = 0; i < len ; ++i)
		{
			CComPtr<IXMLDOMNode> pNode;
			pResult->snapshotItem(i, &pNode);
			GetIndividualHeader(pModel,pNode,mHeaders);
		}
	}
	else
	{
		GetIndividualHeader(pModel,pContext,mHeaders);
	}
	return hr;
}

void CImplHeader::GetIndividualHeader(CImplModel * pModel,IXMLDOMNode * pContext,CComBSTRMap & mHeaders)
{
	CComBSTR sName,sValue;
	m_pNameResolver->GetValue(pModel,pContext,&sName);
	if(sName)
	{
		m_pValueResolver->GetValue(pModel,pContext,&sValue);
		mHeaders[sName] = sValue;
	}
		
}